﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR.Client;
using NanjingbeiRailwayStation.Core;
using NanjingbeiRailwayStation.WebApi.Models;

namespace NanjingbeiRailwayStation.WebApi.Controllers
{
    /// <summary>
    /// web hook 使用
    /// </summary>
    /// 

    [ApiController]
    [Route("[controller]")]
  
    public class WebhookController : ControllerBase
    {

        /// <summary>
        /// 事件上报（ websocket 测试中）
        /// </summary>
        /// <returns></returns>
        /// 
        //[HttpPost("BroadcastEventReport")]
        [HttpPost("BroadcastEventReport")]
        public  async Task BroadcastEventReport(WebhookRequest webhookRequest)
        {

            

            var imei = webhookRequest.imei;

            var hubConnection = new HubConnectionBuilder()
                 .WithUrl(StringConstant.LocalMessageHubUrl)
                 .Build();
             
            await hubConnection.StartAsync();

            await hubConnection.SendAsync(StringConstant.BroadcastEventReport, imei);



        }
        /// <summary>
        /// 实时电参数（websocket 测试中）
        /// </summary>
        /// <returns></returns>

        //[HttpPost("BroadcastRealTimeElectricalParameters")]
        [HttpPost("BroadcastRealTimeElectricalParameters")]
        public async Task BroadcastRealTimeElectricalParameters(WebhookRequest  webhookRequest)
        {
            var imei = webhookRequest.imei;
             

            var hubConnection = new HubConnectionBuilder()
                 .WithUrl(StringConstant.LocalMessageHubUrl)
                 .Build();


            await hubConnection.StartAsync();

            await hubConnection.SendAsync(StringConstant.BroadcastRealTimeElectricalParameters, imei);


             
        }

    }
}
